package br.ufg.inf.sd.truco;

import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.net.UnknownHostException;
import java.rmi.RemoteException;

import javax.swing.JFrame;

/**
 * @version 1.0
 * @author Pedro Henrique e Valemar Neto
 */
public class GUISD extends JFrame implements ItemListener 
{
    
    private javax.swing.JButton botaoComecarJogo;
    private javax.swing.JButton botaoDesisteRodada;
    private javax.swing.JButton botaoTruco;
    private javax.swing.JButton carta1;
    private javax.swing.JButton carta2;
    private javax.swing.JButton carta3;
    private javax.swing.JLabel cartaCorrente1;
    private javax.swing.JLabel cartaCorrente2;
    private javax.swing.JLabel cartaCorrente3;
    private javax.swing.JLabel cartaCorrente4;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField pontuacaoGeralDupla1;
    private javax.swing.JTextField pontuacaoGeralDupla2;
    private javax.swing.JTextField pontuacaoParcialDupla1;
    private javax.swing.JTextField pontuacaoParcialDupla2;
    private java.awt.Checkbox jogarNoEscuro;
    private Cliente cliente;
    private Carta card1;
    private Carta card2;
    private Carta card3;
    private boolean escuro;
	private static final long serialVersionUID = 1L;
	
	/** Creates new form GUISD 
	 * @throws UnknownHostException*/
    public GUISD() throws UnknownHostException 
    {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     * @throws UnknownHostException
     */
    private void initComponents() throws UnknownHostException 
    {
    	jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        carta1 = new javax.swing.JButton();
        botaoDesisteRodada = new javax.swing.JButton();
        botaoTruco = new javax.swing.JButton();
        pontuacaoGeralDupla1 = new javax.swing.JTextField();
        pontuacaoGeralDupla2 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        pontuacaoParcialDupla1 = new javax.swing.JTextField();
        pontuacaoParcialDupla2 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        cartaCorrente1 = new javax.swing.JLabel();
        cartaCorrente2 = new javax.swing.JLabel();
        cartaCorrente3 = new javax.swing.JLabel();
        cartaCorrente4 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        botaoComecarJogo = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        carta2 = new javax.swing.JButton();
        carta3 = new javax.swing.JButton();
        jogarNoEscuro = new java.awt.Checkbox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jogarNoEscuro = new java.awt.Checkbox();
        escuro = false; //default.

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Truco");
        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jLabel1.setText("Chat:");

        carta1.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));
        carta1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        botaoDesisteRodada.setText("Desiste Rodada");

        botaoTruco.setText("Truco");

        pontuacaoGeralDupla1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pontuacaoGeralDupla1.setText("0");
	pontuacaoGeralDupla1.setEditable(false);

        pontuacaoGeralDupla2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pontuacaoGeralDupla2.setText("0");
	pontuacaoGeralDupla2.setEditable(false);

        jLabel2.setText("Dupla1");

        jLabel3.setText("Dupla2");

        jPanel1.setBackground(new java.awt.Color(255, 204, 153));
        jPanel1.setForeground(new java.awt.Color(255, 204, 102));
        jLabel6.setText("jogador1");

        jLabel7.setText("jogador2");

        jLabel8.setText("jogador3");

        jLabel9.setText("jogador4");

        jLabel13.setText("Dupla1");

        pontuacaoParcialDupla1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pontuacaoParcialDupla1.setText("0");
	pontuacaoParcialDupla1.setEditable(false);

        pontuacaoParcialDupla2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pontuacaoParcialDupla2.setText("0");
	pontuacaoParcialDupla2.setEditable(false);

        jLabel14.setText("Dupla2");

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("Pontos da Rodada");

        cartaCorrente1.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));
        cartaCorrente1.setText("jLabel5");

        cartaCorrente2.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));
        cartaCorrente2.setText("jLabel5");

        cartaCorrente3.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));
        cartaCorrente3.setText("jLabel5");

        cartaCorrente4.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));
        cartaCorrente4.setText("jLabel5");

	

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(10, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addComponent(cartaCorrente1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(19, 19, 19)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cartaCorrente2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7)))
                            .addComponent(pontuacaoParcialDupla1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(cartaCorrente3, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(pontuacaoParcialDupla2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(cartaCorrente4, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(134, 134, 134))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(pontuacaoParcialDupla1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pontuacaoParcialDupla2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cartaCorrente3)
                            .addComponent(cartaCorrente4)
                            .addComponent(cartaCorrente2)
                            .addComponent(cartaCorrente1))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        jLabel4.setText("Mesa:");

        botaoComecarJogo.setText("Come\u00e7ar Jogo");

        jLabel16.setText("Suas cartas:");

        jButton2.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));

        carta2.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));
        carta2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        carta3.setIcon(new javax.swing.ImageIcon("./images/verso_mini.JPG"));
        carta3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jogarNoEscuro.setLabel("jogarNoEscuro");

        jMenu1.setText("Jogo");
        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(carta1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(19, 19, 19)
                        .addComponent(carta2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(21, 21, 21)
                        .addComponent(carta3, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel4)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addGap(72, 72, 72)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(pontuacaoGeralDupla1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(16, 16, 16) 
        
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3)
                                    .addComponent(pontuacaoGeralDupla2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(botaoComecarJogo, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                                    .addComponent(botaoDesisteRodada, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                                    .addComponent(botaoTruco, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                                    .addComponent(jogarNoEscuro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(pontuacaoGeralDupla1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(pontuacaoGeralDupla2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(20, 20, 20)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                                .addComponent(jogarNoEscuro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(botaoComecarJogo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botaoDesisteRodada)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botaoTruco))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(carta1)
                                    .addComponent(carta2)
                                    .addComponent(carta3))
                                .addGap(23, 23, 23)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel16)))
                .addContainerGap())
            .addComponent(jButton2)
        );
        pack();
        
        
        /** --------------------- Deixar todos os botoes indisponiveis para nao permitir graca antes
         *  de o jogo comecar.
         * 
         */
        
        botaoDesisteRodada.setEnabled(false);
        botaoTruco.setEnabled(false);
        carta1.setEnabled(false);
        carta2.setEnabled(false);
        carta3.setEnabled(false);
        cartaCorrente1.setEnabled(false);
        cartaCorrente2.setEnabled(false);
        cartaCorrente3.setEnabled(false);
        cartaCorrente4.setEnabled(false);
        
        
        /** ------------------------------ Adicionando Eventos ao botoes e outros componentes GUI ------*/

                   

        //Botao "Comecar Jogo"
        botaoComecarJogo.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        //Botao "Carta numero 1"
        carta1.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt){
                try
		{
            		jButton2ActionPerformed(evt);
		}
                catch(RemoteException e){}
            }
        });

        //Botao "Carta numero 2"
        carta2.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
            	try
		{
                	jButton3ActionPerformed(evt);
		}
            	catch(RemoteException e){}
            }
        });

        //Botao "Carta numero 3"
        carta3.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
            	try
		{
                	jButton7ActionPerformed(evt);
		}
            	catch(RemoteException e){}
            }
        });

        //Botao "Desiste Rodada"
        botaoDesisteRodada.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt) 
            {
            	try
				{
                jButton4ActionPerformed(evt);
				}
            	catch(RemoteException e){}
            }
        });

        //Botao "Truco"
        botaoTruco.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
            	try
				{
                jButton5ActionPerformed(evt);
				}
            	catch(RemoteException e){}
            }
        });
        
        //Adiciona ouvidor ao CheckBox
        jogarNoEscuro.addItemListener(this);
        
        

        /** ----------------- Fim da Adicao de eventos ---------------------------------------------------*/


        
    }// </editor-fold>//GEN-END:initComponents
    
    /** ------------Evento do Botao "Comecar Jogo"  ----------------------------------------------------------*/


    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed

    	try
	{
    	   
    	    botaoComecarJogo.setEnabled(false); //desabilita botao Comecar Jogo	
    	    cliente.comecarJogo(); //conecta ao servidor  
	    
    	
	}
    	catch(RemoteException e){};
		
    	
    	 botaoDesisteRodada.setEnabled(true);
         botaoTruco.setEnabled(true);
         carta1.setEnabled(true);
         carta2.setEnabled(true);
         carta3.setEnabled(true);
         cartaCorrente1.setEnabled(true);
         cartaCorrente2.setEnabled(true);
         cartaCorrente3.setEnabled(true);
         cartaCorrente4.setEnabled(true);
    	
    	

        // Este metodo deve retornar ao cliente
        // um vetor com tres cartas diferentes.

    

    }//GEN-LAST:event_jButton6ActionPerformed

    /** ------------------- Fim do evento do botao "Comecar Jogo" -----------------------------------*/


    /** -------------------- Tratamento de eventos para as cartas disponiveis ao jogador ------------
     * @throws RemoteException*/

    //Carta 1
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) throws RemoteException
    {
          cliente.jogar(card1);	
          carta1.setEnabled(false); //Desabilita a carta se ela ja foi utilizada
    }

    //Carta 2
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) throws RemoteException
    {

          cliente.jogar(card2);	
          carta2.setEnabled(false); //Desabilita a carta se ela ja foi utilizada


    }

    //Carta 3
    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) throws RemoteException
    {
          cliente.jogar(card3);	
          carta3.setEnabled(false); //Desabilita a carta se ela ja foi utilizada

    }


    /** -------------------- Fim do Tratamento de eventos para as cartas disponiveis ao jogador ------------*/

    /** => Tratamento de Eventos para o Botao Desiste Rodada ---------------------------
     * @throws RemoteException*/

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) throws RemoteException
    {
    	cliente.correr();

    }

    /** ----------------------------- Fim Do Tratamento para Desiste Rodada --------------- */

    /** => Tratamento de eventos para o botao Truco ------------------------------------
     * @throws RemoteException*/

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) throws RemoteException
    {
    	/**
    	 * Chama remotamente no servidor o m�todo Truco, modificando a variavel
    	 * isTrucado para que seja TRUE.
    	 * Tratamento do Truco e complexo
    	 * Desabilitar botao Truco: jButton5.setEnabled(false);
    	 */
    	 cliente.truco();
    	 botaoTruco.setEnabled(false);
    	 

    }

    /** ------------------------------ Fim tratamento de eventos Truco ------------------*/

    /**
     * Evento do CheckBox
     */
    public void itemStateChanged(ItemEvent e) 
    {
       
        Object source = e.getItemSelectable();

        if (source == jogarNoEscuro) 
        {
           escuro = true;
        }
    }
    
    
    
    /**
     * Trava as funcionalidades do jogador
     */
    public void travar()
    {
    	// trava as cartas
    	carta1.setEnabled(false);
    	carta2.setEnabled(false);
    	carta3.setEnabled(false);
    	
    	// trava o botao de trucar
    	botaoTruco.setEnabled(false);
        botaoDesisteRodada.setEnabled(false);
        //botaoComecarJogo.setEnabled(false);
        
    }
     
    /**
     * Libera as funcionalidades do jogador
     */
    public void destravar()
    {
    	// libera as cartas
    	carta1.setEnabled(true);
    	carta2.setEnabled(true);
    	carta3.setEnabled(true);
    	
    	// libera o botao de trucar
    	botaoTruco.setEnabled(true);
    	botaoTruco.setText("Truco");
        botaoDesisteRodada.setEnabled(true);
        botaoDesisteRodada.setText("Desiste Rodada");
    }

    /**
     * Exibe que a partida esta trucada
     */
    public void setTruco()
    {
    	// trava o botao de trucar
    	botaoTruco.setEnabled(false);
    	botaoTruco.setBackground( new Color(255, 255, 255) );
    	botaoTruco.setText("Partida Trucada");
    }
     
    /**
     * Atualiza os pontos da partida
     */
    public void setPontos(int dupla, int pts)
    {
    	// atualiza a pontuacao da dupla 1
    	if(dupla == 1)
    		pontuacaoGeralDupla1.setText(String.valueOf(pts));
    	
    	// atualiza a pontuacao da dupla 2
    	else if(dupla == 2)
    		pontuacaoGeralDupla2.setText(String.valueOf(pts));
    }

    public void setPontosParciais(int dupla, int pts){
    	// atualiza a pontuacao da dupla 1
    	if(dupla == 1)
    		pontuacaoParcialDupla1.setText(String.valueOf(pts));
    	
    	// atualiza a pontuacao da dupla 2
    	else if(dupla == 2)
    		pontuacaoParcialDupla2.setText(String.valueOf(pts));

    }
     
    /**
     * Atualiza a pontuacao das particas ( soma-se um ao numero de partidas que a equipe ganhou )
     */
    /*public void setVencedor(int dupla)
    {
    	// atualiza a pontuacao da dupla 1
    	if(dupla == 1){
    		int pts = Integer.parseInt(pontuacaoGeralDupla1.getText());
    		pts++;
    		pontuacaoGeralDupla1.setText(String.valueOf(pts));
    	}
    	
    	// atualiza a pontuacao da dupla 2
    	else if(dupla == 2){
    		int pts = Integer.parseInt(pontuacaoGeralDupla2.getText());
    		pts++;
    		pontuacaoGeralDupla2.setText(String.valueOf(pts));
    	}
    }*/
    
	/*
    * @see JogadorInterface#setCartaJogada(int, Carta)
    */
    public void setCartaJogada(int jogador, Carta carta)
    {
	    String figura = carta.getNome() + "-" + carta.getNipe() +".JPG";
	    
	    switch(jogador)
	    {
		    case 0:
		    	cartaCorrente1.setIcon(new javax.swing.ImageIcon("./images/" + figura));
		    	break;
		
		    case 1:
		    	cartaCorrente2.setIcon(new javax.swing.ImageIcon("./images/" + figura));
		    	break;
		
		    case 2:
		    	cartaCorrente3.setIcon(new javax.swing.ImageIcon("./images/" + figura));
		    	break;
		
		    case 3:
		    	cartaCorrente4.setIcon(new javax.swing.ImageIcon("./images/" + figura));
		    	break;
	    }

    }
	
    /*
    * @see JogadorInterface#resetCartasJogadas()
    */
    public void resetCartasJogadas()
    {
	    javax.swing.ImageIcon figura = new javax.swing.ImageIcon("./images/verso_mini.JPG");
	    cartaCorrente1.setIcon(figura);
	    cartaCorrente2.setIcon(figura);
	    cartaCorrente3.setIcon(figura);
	    cartaCorrente4.setIcon(figura);
    }
    
    /**
	 * Metodo que recebe as cartas do servidor.
	 * As cartas sao passadas a Classe Cliente.
	 * 
	 * @return
	 */
	public void setCartas(Carta[] receber)
    	{

		card1 = receber[0];
		carta1.setIcon(new javax.swing.ImageIcon("./images/" + receber[0].getNome() + "-" + receber[0].getNipe() + ".JPG"));
		card2 = receber[1];
		carta2.setIcon(new javax.swing.ImageIcon("./images/" + receber[1].getNome() + "-" + receber[1].getNipe() + ".JPG"));
		card3 = receber[2];
		carta3.setIcon(new javax.swing.ImageIcon("./images/" + receber[2].getNome() + "-" + receber[2].getNipe() + ".JPG"));

    	}
	
	/**
	 * Metodo utilizado para que a GUI, que � um 
	 * campo da classe Cliente, possa interagir
	 * com os metodos desse proprio cliente.
	 * @param c
	 */
	public void inicializaCliente(Cliente c)
	{
		cliente = c;
	}
  
}